package cn.lili.modules.system.mapper;

import cn.lili.modules.member.entity.dos.CityDistribution;
import cn.lili.modules.system.entity.dos.Region;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 行政地区数据处理层
 *
 * @author Chopper
 * @since 2020/12/8 9:46
 */
public interface RegionMapper extends BaseMapper<Region> {


    @Select(
            "<script> <if test='provinceCode != null and provinceCode != \"\"'>" +
                    "SELECT id AS cityCode, `name` AS cityName FROM li_region " +
                    "WHERE " +
                    "parent_id = #{provinceCode} AND `level` = 'city' " +
                    "</if> " +

                    "<if test='cityCode != null and cityCode != \"\"'>" +
                    "SELECT id AS districtCode,`name` AS districtName FROM li_region " +
                    "WHERE " +
                    " parent_id = #{cityCode} AND `level` = 'district' " +
                    "</if> " +
                    " AND delete_flag = 0" +
                    " ORDER BY order_num,id  </script> ")
    List<CityDistribution> selectCityDistributionCityCodeAnddistrictCodeList(@Param("provinceCode") String provinceCode, @Param("cityCode") String cityCode);
}